{include file="public/header"}
</head>
<body>
	<header>
		<div>
			<a href="javascript:history.back();"><i class="icon-fanhui icon iconfont"></i></a>
		</div>
		<div>
			支付
		</div>
		<div></div>
	</header>
	<div class="main vip" style="margin-top: 12vw;">
		
		<div class="tabContent">
			<div class="orderDetail">
				<div class="orderId">
					<span class="oid">
						订单号：<span id="ordersn">{$line['order_sn']}</span>
					</span>
					
				</div>
				
				<div class="pay">
					
					
					<span class="pprice">
						支付方式：<span>微信</span>
					</span>
					<span class="tprice">
						总金额：<span id="moeny">￥{$line['price']}</span>
					</span>
				</div>
				
			</div>
			<a href="#" class="btn">立即支付</a>
		</div>

	</div>
	<script>

		$('.btn').click(function () {
            // setInterval(aa(),3000);
			if ($(this).text()=='立即支付'){
				var order = $('#ordersn').text();
				$.ajax({
					type: 'post',
					url: '{:url("Good/ajaxBuy")}',
					data: {order:order},
					dataType: 'json',
					success: function (data) {

					    var num = 60;
					    function getTime() {
							if (num==0){
							    alert('二维码过期,请重新刷新页面');
                                num=60;
							    window.location.reload();
							}else {
							    num--;
							}
                        }
                        setInterval(getTime,1000);

                        var img = "<div style='text-align: center'>" +
                            "<span>请在"+num+"秒内完成支付</span><br>" +
                            "<img src='data:image/png;base64,"+data+"' id='erweima'>" +
                            "</div>";
                        $('.orderDetail').append(img);
                        $('.btn').text('确认支付');
                        function query(){
                            $.ajax({
                                type:'post',
                                url:'{:url("Good/ajaxSuccess")}',
                                data: {order:order},
                                dataType:'json',
                                success: function (data) {
                                    if (typeof(data) != "undefined"){
                                        if (data['status']=="1"){
                                            alert('支付成功');
                                            location.href="../User/user";
                                        }else if (data['status']=="2"){
                                            alert(data['msg']);
                                            window.location.reload();
                                        }else{
                                            window.location.reload();
                                        }
                                    }
                                }
                            })
                        }
						setInterval(query,3000);
					}
				});
			}
			// else if($(this).text()=='确认支付'){
             //    var order = $('#ordersn').text();
             //    $.ajax({
             //        type: 'post',
             //        url: '{:url("Good/ajaxSuccess")}',
             //        data: {order:order},
             //        dataType: 'json',
             //        success: function (data) {
             //            console.log(data);
             //            if (data['status']==0){
             //                $('#erweima').remove();
             //                alert(data['msg']);
             //                $('.btn').text('立即支付');
             //                // location.href="User/user";
             //            }
             //        }
             //    });
            //
			// }

		})

	</script>
	{include file="public/footer"}
</body>
</html>